package org.recruit.system.controller;

import java.util.List;

import org.recruit.system.domain.Company;
import org.recruit.system.service.ICompanyService;
import org.recruit.system.utils.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 公司Controller
 *
 * @author teapot
 * @date 2020-11-12
 */
@Controller
@RequestMapping("/system/company")
public class CompanyController {
    private String prefix = "system/company";

    @Autowired
    private ICompanyService companyService;


    @GetMapping()
    public String company() {
        return prefix + "/company";
    }

    /**
     * 查询公司列表
     */
    @PostMapping("/list")
    @ResponseBody
    public AjaxResult list(Company company) {
        //startPage();
        List<Company> list = companyService.selectCompanyList(company);
        return AjaxResult.success(list);
    }

    /**
     * 新增公司
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存公司
     */
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Company company) {
        return AjaxResult.success(companyService.insertCompany(company));
    }

    /**
     * 修改公司
     */
    @GetMapping("/edit/{companyId}")
    public String edit(@PathVariable("companyId") Long companyId, ModelMap mmap) {
        Company company = companyService.selectCompanyById(companyId);
        mmap.put("company", company);
        return prefix + "/edit";
    }

    /**
     * 修改保存公司
     */
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Company company) {
        return AjaxResult.success(companyService.updateCompany(company));
    }

    /**
     * 删除公司
     */
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return AjaxResult.success(companyService.deleteCompanyByIds(ids));
    }
}
